using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;

namespace SqlTools.SchemaReader
{
	public class StoredProcedure : DbTextObject
	{
		private DbCollection<Parameter> _parameters = null;

		public StoredProcedure() : this("", 0) { }

		public StoredProcedure(string name, int id)
			: base(name, id)
		{
			this._parameters = new DbCollection<Parameter>();
		}

		public DbCollection<Parameter> Parameters
		{
			get { return _parameters; }
		}

		public override DbObjectType Type
		{
			get { return DbObjectType.StoredProcedure; }
		}

		public override void SaveXml(XmlDocument doc, XmlNode xmlParent)
		{
			XmlElement el = CreateXmlElement(doc, xmlParent);

			this._parameters.SaveXml(doc, el);
		}

		public override void LoadXml(XmlElement el, Database db)
		{
			base.LoadXml(el, db);

			XmlNodeList nodes = el.GetElementsByTagName(_parameters.XmlElementName);
			
			if ( nodes.Count > 0 )
				_parameters.LoadXml(nodes[0] as XmlElement, db);
		}
	}
}
